package com.my_musc_service.controller;

import com.my_musc_service.common.R;
import com.my_musc_service.entity.Comment;
import com.my_musc_service.entity.TopComment;
import com.my_musc_service.service.CommentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Comment)表控制层
 *
 * @author A.Dun
 * @since 2021-08-11 12:13:04
 */
@Deprecated
@Slf4j
@RestController
@RequestMapping("comment")
public class CommentController {
    /**
     * 服务对象
     */
    @Resource
    private CommentService commentService;

    private R isOK(boolean flag) {
        if (flag) {
            return R.ok();
        } else {
            return R.error();
        }
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public R selectOne(Integer id) {
        Comment comment = this.commentService.queryById(id);
        return R.ok().data("comment", comment);
    }

    @PostMapping("save")
    public R saveComment(@RequestBody Comment comment) {
        boolean flag = commentService.save(comment);
        return isOK(flag);
    }


    @GetMapping("getComment")
    public R getCommentVOByCommentId(@RequestParam(value = "id", required = false) Integer id,
                                     @RequestParam(value = "songListId", required = false) Integer songListId,
                                     @RequestParam(value = "songId", required = false) Integer songId) {
        TopComment topComment = commentService.getCommentVOByCommentId(id,songListId,songId);
        return R.ok().data("commentList", topComment);
    }


}

